import {
	createRouter,
	createWebHashHistory
} from 'vue-router'
import HomeView from '@/views/HomeView.vue'

const routes = [{
		path: '/',
		name: 'home',
		component: HomeView,
		meta: {
			title: '首页'
		}
	},
	{
		path: '/newbookup',
		name: 'newbookup',
		component: () => import('@/views/NewbookupView.vue'),
		meta: {
			title: '新书上架'
		}
	},
	{
		path: '/specialbook',
		name: 'specialbook',
		component: () => import('@/views/SpecialBookView.vue'),
		meta: {
			title: '特价书'
		}
	},
	{
		path: '/memberchange',
		name: 'memberchange',
		component: () => import('@/views/MemberUpdateView.vue'),
		meta: {
			title: '会员修改'
		}
	},
	{
		path: '/balance',
		name: 'balance',
		component: () => import('@/views/SalesrankView.vue'),
		meta: {
			title: '销售排行'
		}
	},
	{
		path: '/shopping',
		name: 'shopping',
		component: () => import('@/views/ShoppingCart.vue'),
		meta: {
			title: '购物车'
		}
	},
	{
		path: '/orderform',
		name: 'orderform',
		component: () => import('@/views/OrderformView.vue'),
		meta: {
			title: '查看订单'
		}
	},
	{
		path: '/adminman',
		name: 'adminman',
		component: () => import('@/views/AdminView.vue'),
		meta: {
			title: '管理员后台'
		}
	},
	{
		path: '/detail',
		name: 'detail',
		component: () => import('@/components/Detail.vue'),
		meta: {
			title: '书本详情'
		}
	},
]

const router = createRouter({
	history: createWebHashHistory(),
	routes
})

router.beforeEach((to, from, next) => {
	/* 路由发生变化修改页面title */
	if (to.meta.title) {
		document.title = to.meta.title
	}
	next()
})

export default router
